package cn.alise.util;

import java.io.Serializable;

/**
 * JSONResult.java
 * 
 * @des HTTP调用返回结果格式对象
 * @author Chunjie He
 * @version 1.0
 */
public class JSONResult implements Serializable {
	private static final long serialVersionUID = -5659334745091167415L;

	/**
	 * 返回状态： 0 成功   !0失败
	 */
	private int status;

	/**
	 * 成功时的描述信息
	 */
	private String message;

	/**
	 * 失败对象：如果状态返回失败，那么需要描述失败编号
	 * 和失败的语言描述
	 */
	private Error error;

	/**
	 * 返回的结果集合信息
	 */
	private Object data = "";
	
	public JSONResult() {
	}
	
	public JSONResult(String message) {
		this.status = 0;
		this.message = message;
	}
	
	public JSONResult(int status, Object data, String message) {
		this.status = status;
		this.message = message;
		this.data = data;
	}
	
	public JSONResult(String code, String errorMsg) {
		this.status = -1;
		this.error = new Error();
		this.error.setCode(code);
		this.error.setErrorMsg(errorMsg);
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Error getError() {
		return error;
	}

	public void setError(Error error) {
		this.error = error;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	/**
	 * 错误对象
	 * @author Chunjie He
	 */
	public class Error implements Serializable {
		private static final long serialVersionUID = 1L;

		/**
		 * 错误编码
		 */
		private String code;

		/**
		 * 错误描述
		 */
		private String errorMsg;

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getErrorMsg() {
			return errorMsg;
		}

		public void setErrorMsg(String errorMsg) {
			this.errorMsg = errorMsg;
		}
	}
}
